package org.game.db.bean;

import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import org.apache.commons.lang3.ArrayUtils;
import org.game.db.cache.RechargeOrderCache;
import com.sojoys.artifact.build.data.base.BasePojo;
import java.sql.SQLException;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.tools.ToolCopy;
import org.game.db.cache.PlayerCache;
import java.sql.ResultSet;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import static org.game.db.StaticResource.RechargeOrderResource.*;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import static org.game.db.StaticResource.RechargeOrderResource.*;
/**
 * 订单
 */
public class RechargeOrder extends BasePojo<RechargeOrder> {
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[2];
	
	/**
	* id
	*/
	private String id;
	
	/**
	* create_date
	*/
	private java.util.Date createDate;
	
	/**
	* modified_date
	*/
	private java.util.Date modifiedDate;
	
	/**
	* 商品id
	*/
	private int goodsId;
	
	/**
	* 玩家id
	*/
	private int playerId;
	
	
	@Deprecated
	public static RechargeOrder builder() {
		RechargeOrder rechargeOrder = new RechargeOrder();
		return rechargeOrder;
	}
	
	@Deprecated
	public RechargeOrder() {
		super();
	}
	
	public RechargeOrder(String id, int goodsId, int playerId) {
		super();
		this.id = id;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
		this.goodsId = goodsId;
		this.playerId = playerId;
	}
	
	/**
	 * id
	 */
	public String getId() {return id;}
	
	/**
	 * id
	 */
	public RechargeOrder setId(String id) {this.id = id;return this;}
	
	/**
	 * create_date
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * create_date
	 */
	protected RechargeOrder setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * modified_date
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * modified_date
	 */
	protected RechargeOrder setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	/**
	 * 商品id
	 */
	public int getGoodsId() {return goodsId;}
	
	/**
	 * 商品id
	 */
	public RechargeOrder setGoodsId(int goodsId) {this.goodsId = goodsId;return this;}
	
	/**
	 * 玩家id
	 */
	public int getPlayerId() {return playerId;}
	
	/**
	 * 玩家id
	 */
	public RechargeOrder setPlayerId(int playerId) {this.playerId = playerId;return this;}
	
	
	// 代理
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.createDate;
        values[2] = this.modifiedDate;
        values[3] = this.goodsId;
        values[4] = this.playerId;
        return values;
	}
	
	public RechargeOrder deepCopy(){
		RechargeOrder rechargeOrder = null;
		try {
			rechargeOrder = (RechargeOrder) super.clone();
		    rechargeOrder.setCreateDate(ToolCopy.copyObject(this.createDate));
		    rechargeOrder.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    // 克隆索引
		    rechargeOrder.indexValues = ArrayUtils.clone(indexValues);
			return rechargeOrder;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return rechargeOrder;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.createDate);
        map.put(keys[2], this.modifiedDate);
        map.put(keys[3], this.goodsId);
        map.put(keys[4], this.playerId);
        return map;
    }
    
    protected RechargeOrder createForMap(Object[] keys,Map map){
   		this.id = (String)map.get(keys[0]);
   		this.createDate = (java.util.Date)map.get(keys[1]);
   		this.modifiedDate = (java.util.Date)map.get(keys[2]);
   		this.goodsId = (int)map.get(keys[3]);
   		this.playerId = (int)map.get(keys[4]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.createDate);
        obj.put(keys[2], this.modifiedDate);
        obj.put(keys[3], this.goodsId);
        obj.put(keys[4], this.playerId);
        return obj;
    }
    
    protected RechargeOrder createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getString(keys[0]);
	    this.createDate = obj.getDate(keys[1]);
	    this.modifiedDate = obj.getDate(keys[2]);
	    this.goodsId = obj.getIntValue(keys[3]);
	    this.playerId = obj.getIntValue(keys[4]);
        return this;
    }
    
    
    public RechargeOrder createForResultSet(ResultSet rs) throws SQLException{
	    this.id = rs.getString(SOURCE_COLUMN_NAMES[0]);
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[1]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[2]);
	    this.goodsId = rs.getInt(SOURCE_COLUMN_NAMES[3]);
	    this.playerId = rs.getInt(SOURCE_COLUMN_NAMES[4]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeString(this.id);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
	    byteBuf.writeInt(this.goodsId);
	    byteBuf.writeInt(this.playerId);
    }
	
	protected RechargeOrder readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readString(null);
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    this.goodsId = byteBuf.readInt(null);
	    this.playerId = byteBuf.readInt(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		return true;
    }
    
	/** 取得[player]*/
	public Player getPlayerPkPlayerId(){
		return PlayerCache.me().getById(playerId);
	}
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public RechargeOrder insert(){
    	return RechargeOrderCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public RechargeOrder update(){
    	return RechargeOrderCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return RechargeOrderCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public RechargeOrder insertAndFlush(){
    	return RechargeOrderCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public RechargeOrder updateAndFlush(){
    	return RechargeOrderCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return RechargeOrderCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public RechargeOrder syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		indexValues[1] = SK_Plus.b(getPlayerId()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getId();
	}
	
	protected void setPrimaryKey(Object key){
		setId((String)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}